package org.water.garden.activity.account;

import org.water.garden.core.ImUtils;
import org.water.garden.core.Intents;
import org.water.garden.view.ActivityListAdapter;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;

/**
 * @author sshwsfc@gmail.com
 * 
 * Show account menu for edit and change status etc.
 */
public class AccountMenu extends ListActivity {

	private ListAdapter adapter;
	
	protected void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		adapter = new ActivityListAdapter(this, getTargetIntent());
		setListAdapter(adapter);
	}

	protected void onListItemClick(ListView l, View v, int position, long id) {
		Intent intent = ((ActivityListAdapter) adapter).intentForPosition(position);
		intent.setData(getIntent().getData());
		startActivity(intent);
		finish();
	}

	protected Intent getTargetIntent() {
		Intent intent = new Intent(Intents.SHOW_ACCOUNT_MENU);

		String providerName = ImUtils.queryProviderName(getContentResolver(), getIntent().getData());
		if(null != providerName){
			intent.addCategory(Intents.CATEGORY_PROVIDER_PREFIX + providerName);
		}
		
		return intent;
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		finish();
		return super.onTouchEvent(event);
	}
	
}
